﻿function onOpen() 
{
  if (options.getValue('dialog_type') == 'change_ring_design') /* event handling for the dialog to change ring colors */
  {
    colorChangerDiv.visible = true;
    addRemoveRingDiv.visible = false;

     radio0.value = (options.getValue("option0") == true);
     radio1.value = (options.getValue("option1") == true);
     radio2.value = (options.getValue("option2") == true);
     radio3.value = (options.getValue("option3") == true);
     radio4.value = (options.getValue("option4") == true);
     options.putValue("OkChangeColor",false);
  }

  else /* event handling for the dialog to add/remove rings */
  {
    colorChangerDiv.visible = false;
    addRemoveRingDiv.visible = true;

    checkbox0.value = (options.getValue("checkbox0") == true);
    checkbox1.value = (options.getValue("checkbox1") == true);
    checkbox2.value = (options.getValue("checkbox2") == true);
    checkbox3.value = (options.getValue("checkbox3") == true);
    checkbox4.value = (options.getValue("checkbox4") == true);
    checkbox5.value = (options.getValue("checkbox5") == true);
    options.putValue("OkChangeRings",false);
    
  } 
}


function onOk() 
{
  if (options.getValue('dialog_type') == 'change_ring_design') /* event handling for the dialog to change ring colors */
  {
   
    if (!radio0.value && !radio1.value && !radio2.value && !radio3.value && !radio4.value)
    {
      prompt.color = "#FF0000";
	    event.returnValue = false;
	    return false;
    }

    options.putValue("option0", radio0.value ? true : false);
    options.putValue("option1", radio1.value ? true : false);
    options.putValue("option2", radio2.value ? true : false);
    options.putValue("option3", radio3.value ? true : false);
    options.putValue("option4", radio4.value ? true : false);
    options.putValue("OkChangeColor",true);
  }

  else /* event handling for the dialog to add/remove rings */
  {
    if (!checkbox0.value && !checkbox1.value && !checkbox2.value &&
      !checkbox3.value && !checkbox4.value && !checkbox5.value) 
    {
      prompt.color = "#FF0000";
      event.returnValue = false;
      return false;
    }

    // Save all the settings only if required
    options.putValue("checkbox0", checkbox0.value ? true : false);
    options.putValue("checkbox1", checkbox1.value ? true : false);
    options.putValue("checkbox2", checkbox2.value ? true : false);
    options.putValue("checkbox3", checkbox3.value ? true : false);
    options.putValue("checkbox4", checkbox4.value ? true : false);
    options.putValue("checkbox5", checkbox5.value ? true : false);
    options.putValue("OkChangeRings", true);

   
  }
}

/**
 * Closes the options dialog and does nothing
 */
function onCancel() {}
